package com.myproject.sbp.order.service.impl;

import com.myproject.sbp.base.common.RespCommon;
import com.myproject.sbp.order.api.feign.MemberServiceFeign;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ywh
 */
@RestController
public class OrderServiceImpl {
    @Resource
    private MemberServiceFeign memberServiceFeigin;

    /**
     * 没有解决服务雪崩效应
     */
    @RequestMapping("/orderToUserInfo")
    public RespCommon orderToUserInfo() {
        // 线程名称组合： 使用通过线程池名称+线程id组合
        System.out.println("orderToUserInfo:" + "当前线程池名称:" + Thread.currentThread().getName());
        return RespCommon.success(memberServiceFeigin.queryMemberList());
    }

    /**
     * 使用Hystrix解决服务雪崩效应
     */
    @HystrixCommand(fallbackMethod = "queryMemberListFallback")
    @RequestMapping("/orderHystrix")
    public RespCommon orderHystrix() {
        System.out.println("orderHystrix:" + "当前线程池名称:" + Thread.currentThread().getName());
        return RespCommon.success(memberServiceFeigin.queryMemberList());
    }

    @RequestMapping("/queryMemberListFallback")
    public RespCommon orderToUserInfoFallback() {
        return RespCommon.error();
    }

}